// Copyright (c) 1997-2003 Eric Orilla. All Rights Reserved.
// email: eorilla@hotmail.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions of source code must have a specific prior written
//    permission from the copyright holder.
//
// 3. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in
//    the documentation and/or other materials provided with the
//    distribution. Alternately, the copyright notice must appear in 
//    the software itself, where it should normally appear.
//
// 4. Neither the name of the copyright holder or the names of contributors
//    may be used to endorse or promote products derived from this software
//    without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// You acknowledge that Software is not designed, licensed or intended for
// use in the design, construction, operation or maintenance of any facility
// with high risk to any form of life and the environment.

unit INI_Database;

interface
uses
  SysUtils, INI_Section;

const
  IniSecDatabase                = 'Database';
  IniSecDatabaseRemote          = 'DatabaseRemote';

  IniIDPPath                    = 'PPath';      //parameter database path
  IniIDXPath                    = 'XPath';      //transaction database path
  IniIDXPathA                   = 'XPathA';      //transaction database path
  IniIDXPathB                   = 'XPathB';      //transaction database path
  IniIDMPPath                   = 'MPPath';     //master parameter database path
  IniIDMXPath                   = 'MXPath';     //master transaction database path
  IniIDXLogPath                 = 'XLogPath';   //transaction log path
  IniIDOCBTPath                 = 'OCBTPath';   //open checks by table path
  IniIDOCBSPath                 = 'OCBSPath';   //open checks by sequence path
  IniIDOCBCPath                 = 'OCBCPath';   //open checks by customer path
  IniIDServerOCBTPath           = 'SOCBTPath';  //server open checks by table path
  IniIDServerOCBSPath           = 'SOCBSPath';  //server open checks by sequence path
  IniIDServerOCBCPath           = 'SOCBCPath';  //server open checks by customer path
  IniIDTempDBPath               = 'TempDBPath';  //server open checks by customer path
  IniIDTempDBPathMXDB           = 'mxdb';
  IniIDTempDBPathMPDB           = 'mpdb';
  IniIDTempDBPathXDB            = 'xdb';
  IniIDTempDBPathPDB            = 'pdb';
  IniIDTempDBPathDatabase       = 'database';
  IniIDReportDocumentPath       = 'RepDocPath';

type
  EOIniSectionDatabase = class(EOIniSection)
  private
{
    FPPath: String;
    FXPath: String;
    FXPathA: String;
    FXPathB: String;
    FMPPath: String;
    FMXPath: String;
    FXLogPath: String;
    FOpenCheckByTablePath: String;
    FOpenCheckBySequencePath: String;
    FOpenCheckByCustomerPath: String;
    FServerOpenCheckByTablePath: String;
    FServerOpenCheckBySequencePath: String;
    FServerOpenCheckByCustomerPath: String;
    FTempDBPath: String;
    FTempDBPathMXDB: String;
    FTempDBPathMPDB: String;
    FTempDBPathXDB: String;
    FTempDBPathPDB: String;
    FTempDBPathDatabase: String;
}

    function GetPPath: String;
    procedure SetPPath(Value: String);

    function GetXPath: String;
    procedure SetXPath(Value: String);

    function GetXPathA: String;
    procedure SetXPathA(Value: String);

    function GetXPathB: String;
    procedure SetXPathB(Value: String);

    function GetMPPath: String;
    procedure SetMPPath(Value: String);
    function GetMXPath: String;
    procedure SetMXPath(Value: String);

    function GetXLogPath: String;
    procedure SetXLogPath(Value: String);

    function GetOpenCheckByTablePath: String;
    procedure SetOpenCheckByTablePath(Value: String);
    function GetOpenCheckBySequencePath: String;
    procedure SetOpenCheckBySequencePath(Value: String);
    function GetOpenCheckByCustomerPath: String;
    procedure SetOpenCheckByCustomerPath(Value: String);

    function GetServerOpenCheckByTablePath: String;
    procedure SetServerOpenCheckByTablePath(Value: String);
    function GetServerOpenCheckBySequencePath: String;
    procedure SetServerOpenCheckBySequencePath(Value: String);
    function GetServerOpenCheckByCustomerPath: String;
    procedure SetServerOpenCheckByCustomerPath(Value: String);

    function GetTempDBPath: String;
    procedure SetTempDBPath(Value: String);

    function GetTempDBPathMXDB: String;
    procedure SetTempDBPathMXDB(Value: String);

    function GetTempDBPathMPDB: String;
    procedure SetTempDBPathMPDB(Value: String);

    function GetTempDBPathXDB: String;
    procedure SetTempDBPathXDB(Value: String);

    function GetTempDBPathPDB: String;
    procedure SetTempDBPathPDB(Value: String);

    function GetTempDBPathDatabase: String;
    procedure SetTempDBPathDatabase(Value: String);

    function GetRepDocPath: String;
    procedure SetRepDocPath(Value: String);

  public
    property PPath: String read GetPPath write SetPPath;
    property XPath: String read GetXPath write SetXPath;
    property XPathA: String read GetXPathA write SetXPathA;
    property XPathB: String read GetXPathB write SetXPathB;
    property MPPath: String read GetMPPath write SetMPPath;
    property MXPath: String read GetMXPath write SetMXPath;
    property XLogPath: String read GetXLogPath write SetXLogPath;
    property OpenCheckByTablePath: String read GetOpenCheckByTablePath write SetOpenCheckByTablePath;
    property OpenCheckBySequencePath: String read GetOpenCheckBySequencePath write SetOpenCheckBySequencePath;
    property OpenCheckByCustomerPath: String read GetOpenCheckByCustomerPath write SetOpenCheckByCustomerPath;
    property ServerOpenCheckByTablePath: String read GetServerOpenCheckByTablePath write SetServerOpenCheckByTablePath;
    property ServerOpenCheckBySequencePath: String read GetServerOpenCheckBySequencePath write SetServerOpenCheckBySequencePath;
    property ServerOpenCheckByCustomerPath: String read GetServerOpenCheckByCustomerPath write SetServerOpenCheckByCustomerPath;
    property TempDBPath: String read GetTempDBPath write SetTempDBPath;

    property TempDBPathMXDB: String read GetTempDBPathMXDB write SetTempDBPathMXDB;
    property TempDBPathMPDB: String read GetTempDBPathMPDB write SetTempDBPathMPDB;
    property TempDBPathXDB: String read GetTempDBPathXDB write SetTempDBPathXDB;
    property TempDBPathPDB: String read GetTempDBPathPDB write SetTempDBPathPDB;
    property TempDBPathDatabase: String read GetTempDBPathDatabase write SetTempDBPathDatabase;

    property RepDocPath: String read GetRepDocPath write SetRepDocPath;
{
    property PPath: String read FPPath;
    property XPath: String read FXPath;
    property XPathA: String read FXPathA;
    property XPathB: String read FXPathB;
    property MPPath: String read FMPPath;
    property MXPath: String read FMXPath;
    property XLogPath: String read FXLogPath;
    property OpenCheckByTablePath: String read FOpenCheckByTablePath;
    property OpenCheckBySequencePath: String read FOpenCheckBySequencePath;
    property OpenCheckByCustomerPath: String read FOpenCheckByCustomerPath;
    property ServerOpenCheckByTablePath: String read FServerOpenCheckByTablePath;
    property ServerOpenCheckBySequencePath: String read FServerOpenCheckBySequencePath;
    property ServerOpenCheckByCustomerPath: String read FServerOpenCheckByCustomerPath;
    property TempDBPath: String read FTempDBPath;
    property TempDBPathMXDB: String read FTempDBPathMXDB;
    property TempDBPathMPDB: String read FTempDBPathMPDB;
    property TempDBPathXDB: String read FTempDBPathXDB;
    property TempDBPathPDB: String read FTempDBPathPDB;
    property TempDBPathDatabase: String read FTempDBPathDatabase;

}
    constructor Create(IniSection: String); override;

  end;

  function getInstance: EOIniSectionDatabase;
  function getInstanceRemote: EOIniSectionDatabase;

implementation

function EOIniSectionDatabase.GetPPath: String;
begin
  Result := ReadString(IniIdPPath, '..\database\');
  if Result[Length(Result)] <> PathDelim then
    SetPPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetPPath(Value: String);
begin
  WriteString(IniIdPPath, Value);
end;

function EOIniSectionDatabase.GetXPath: String;
begin
  Result := ReadString(IniIdXPath, '..\XDB\');
  if Result[Length(Result)] <> PathDelim then
    SetXPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetXPath(Value: String);
begin
  WriteString(IniIdXPath, Value);
end;



function EOIniSectionDatabase.GetXPathA: String;
begin
  Result := ReadString(IniIdXPathA, '..\XDBA\');
  if Result[Length(Result)] <> PathDelim then
    SetXPathA(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetXPathA(Value: String);
begin
  WriteString(IniIdXPathA, Value);
end;

function EOIniSectionDatabase.GetXPathB: String;
begin
  Result := ReadString(IniIdXPathB, '..\XDBB\');
  if Result[Length(Result)] <> PathDelim then
    SetXPathB(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetXPathB(Value: String);
begin
  WriteString(IniIdXPathB, Value);
end;



function EOIniSectionDatabase.GetMPPath: String;
begin
  Result := ReadString(IniIdMPPath, '..\MPDB\');
  if Result[Length(Result)] <> PathDelim then
    SetMPPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetMPPath(Value: String);
begin
  WriteString(IniIdMPPath, Value);
end;

function EOIniSectionDatabase.GetMXPath: String;
begin
  Result := ReadString(IniIdMXPath, '..\MXDB\');
  if Result[Length(Result)] <> PathDelim then
    SetMXPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetMXPath(Value: String);
begin
  WriteString(IniIdMXPath, Value);
end;

function EOIniSectionDatabase.GetXLogPath: String;
begin
  Result := ReadString(IniIdXLogPath, '..\Log\');
  if Result[Length(Result)] <> PathDelim then
    SetXLogPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetXLogPath(Value: String);
begin
  WriteString(IniIdXLogPath, Value);
end;

function EOIniSectionDatabase.GetOpenCheckByTablePath: String;
begin
  Result := ReadString(IniIDOCBTPath, '..\CheckTable\');
  if Result[Length(Result)] <> PathDelim then
    SetOpenCheckByTablePath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetOpenCheckByTablePath(Value: String);
begin
  WriteString(IniIDOCBTPath, Value);
end;

function EOIniSectionDatabase.GetOpenCheckBySequencePath: String;
begin
  Result := ReadString(IniIDOCBSPath, '..\CheckSequence\');
  if Result[Length(Result)] <> PathDelim then
    SetOpenCheckBySequencePath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetOpenCheckBySequencePath(Value: String);
begin
  WriteString(IniIDOCBSPath, Value);
end;

function EOIniSectionDatabase.GetOpenCheckByCustomerPath: String;
begin
  Result := ReadString(IniIDOCBCPath, '..\CheckCustomer\');
  if Result[Length(Result)] <> PathDelim then
    SetOpenCheckByCustomerPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetOpenCheckByCustomerPath(Value: String);
begin
  WriteString(IniIDOCBCPath, Value);
end;

function EOIniSectionDatabase.GetServerOpenCheckByTablePath: String;
begin
  Result := ReadString(IniIDServerOCBTPath, '..\CheckTable\');
  if Result[Length(Result)] <> PathDelim then
    SetServerOpenCheckByTablePath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetServerOpenCheckByTablePath(Value: String);
begin
  WriteString(IniIDServerOCBTPath, Value);
end;

function EOIniSectionDatabase.GetServerOpenCheckBySequencePath: String;
begin
  Result := ReadString(IniIDServerOCBSPath, '..\CheckSequence\');
  if Result[Length(Result)] <> PathDelim then
    SetServerOpenCheckBySequencePath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetServerOpenCheckBySequencePath(Value: String);
begin
  WriteString(IniIDServerOCBSPath, Value);
end;

function EOIniSectionDatabase.GetServerOpenCheckByCustomerPath: String;
begin
  Result := ReadString(IniIDServerOCBCPath, '..\CheckCustomer\');
  if Result[Length(Result)] <> PathDelim then
    SetServerOpenCheckByCustomerPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetServerOpenCheckByCustomerPath(Value: String);
begin
  WriteString(IniIDServerOCBCPath, Value);
end;

function EOIniSectionDatabase.GetTempDBPath: String;
begin
  Result := ReadString(IniIDTempDBPath, '..\TempDB\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPath(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPath(Value: String);
begin
  WriteString(IniIDTempDBPath, Value);
end;

function EOIniSectionDatabase.GetTempDBPathMXDB: String;
begin
  Result := ReadString(IniIDTempDBPathMXDB, 'mxdb\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPathMXDB(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPathMXDB(Value: String);
begin
  WriteString(IniIDTempDBPathMXDB, Value);
end;

function EOIniSectionDatabase.GetTempDBPathMPDB: String;
begin
  Result := ReadString(IniIDTempDBPathMPDB, 'mpdb\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPathMPDB(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPathMPDB(Value: String);
begin
  WriteString(IniIDTempDBPathMPDB, Value);
end;

function EOIniSectionDatabase.GetTempDBPathXDB: String;
begin
  Result := ReadString(IniIDTempDBPathXDB, 'xdb\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPathXDB(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPathXDB(Value: String);
begin
  WriteString(IniIDTempDBPathXDB, Value);
end;

function EOIniSectionDatabase.GetTempDBPathPDB: String;
begin
  Result := ReadString(IniIDTempDBPathPDB, 'pdb\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPathPDB(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPathPDB(Value: String);
begin
  WriteString(IniIDTempDBPathPDB, Value);
end;

function EOIniSectionDatabase.GetTempDBPathDatabase: String;
begin
  Result := ReadString(IniIDTempDBPathDatabase, 'database\');
  if Result[Length(Result)] <> PathDelim then
    SetTempDBPathDatabase(Result + PathDelim);
end;

procedure EOIniSectionDatabase.SetTempDBPathDatabase(Value: String);
begin
  WriteString(IniIDTempDBPathDatabase, Value);
end;

function EOIniSectionDatabase.GetRepDocPath: String;
begin
  Result := ReadString(IniIDReportDocumentPath, '..\Reports\');
end;

procedure EOIniSectionDatabase.SetRepDocPath(Value: String);
begin
  WriteString(IniIDReportDocumentPath, Value);
end;

constructor EOIniSectionDatabase.Create(IniSection: String);
begin
  Inherited;

{
  FPPath                          := GetPPath;
  FXPath                          := GetXPath;
  FXPathA                         := GetXPathA;
  FXPathB                         := GetXPathB;
  FMPPath                         := GetMPPath;
  FMXPath                         := GetMXPath;
  FXLogPath                       := GetXLogPath;
  FOpenCheckByTablePath           := GetOpenCheckByTablePath;
  FOpenCheckBySequencePath        := GetOpenCheckBySequencePath;
  FOpenCheckByCustomerPath        := GetOpenCheckByCustomerPath;
  FServerOpenCheckByTablePath     := GetServerOpenCheckByTablePath;
  FServerOpenCheckBySequencePath  := GetServerOpenCheckBySequencePath;
  FServerOpenCheckByCustomerPath  := GetServerOpenCheckByCustomerPath;
  FTempDBPath                     := GetTempDBPath;
  FTempDBPathMXDB                 := GetTempDBPathMXDB;
  FTempDBPathMPDB                 := GetTempDBPathMPDB;
  FTempDBPathXDB                  := GetTempDBPathXDB;
  FTempDBPathPDB                  := GetTempDBPathPDB;
  FTempDBPathDatabase             := GetTempDBPathDatabase;
}

  ForceDirectories(GetPPath);
  ForceDirectories(GetXPath);
  ForceDirectories(GetXPathA);
  ForceDirectories(GetXPathB);
  ForceDirectories(GetMPPath);
  ForceDirectories(GetMXPath);
  ForceDirectories(GetXLogPath);
  ForceDirectories(GetOpenCheckByTablePath);
  ForceDirectories(GetOpenCheckBySequencePath);
  ForceDirectories(GetOpenCheckByCustomerPath);
  ForceDirectories(GetServerOpenCheckByTablePath);
  ForceDirectories(GetServerOpenCheckBySequencePath);
  ForceDirectories(GetServerOpenCheckByCustomerPath);
  ForceDirectories(GetTempDBPath);
  ForceDirectories(GetTempDBPath + GetTempDBPathMXDB);
  ForceDirectories(GetTempDBPath + GetTempDBPathMPDB);
  ForceDirectories(GetTempDBPath + GetTempDBPathXDB);
  ForceDirectories(GetTempDBPath + GetTempDBPathPDB);
  ForceDirectories(GetTempDBPath + GetTempDBPathDatabase);
  ForceDirectories(GetRepDocPath);
end;

var
  IniSectionDatabase: EOIniSectionDatabase;
  IniSectionDatabaseRemote: EOIniSectionDatabase;

function getInstance: EOIniSectionDatabase;
begin
  if IniSectionDatabase = Nil then
    IniSectionDatabase := EOIniSectionDatabase.Create(IniSecDatabase);
  Result := IniSectionDatabase;
end;

function getInstanceRemote: EOIniSectionDatabase;
begin
  if IniSectionDatabaseRemote = Nil then
    IniSectionDatabaseRemote := EOIniSectionDatabase.Create(IniSecDatabaseRemote);

  Result := IniSectionDatabaseRemote;
end;

end.
